#ifndef FUNCTION_CODE_H
#define FUNCTION_CODE_H

#include <QtCore>

//ModbusTCP通讯报文中的功能码字节内容
class CFunctionCode
{
private:
    CFunctionCode();
    ~CFunctionCode();

public:
    enum eFunctionCode{//定义标准modbus功能码枚举
    //读寄存器
    READ_01_COIL                           = 0x01, //读线圈，coil开关量输出
    READ_02_INPUT                          = 0x02, //读输入离散量，discrete input，开关量输入
    READ_03_HOLD_REGISTERS                 = 0x03, //读保持寄存器，holding register，可读写寄存器
    READ_04_INPUT_REGISTERS                = 0x04, //读输入寄存器，input register，模拟量输入
    //写寄存器
    WRITE_05_ONE_COIL                      = 0x05, //写单个线圈
    WRITE_06_ONE_HOLD_REGISTER             = 0x06, //写单个保持寄存器，holding register
    WRITE_10_SOME_HOLD_REGISTERS           = 0x10, //写多个保持寄存器，holding register
    };

public:
    static QString GetName(int iFunctionCode);//获取功能码文字说明

    static bool IsRead(int iFunctionCode);
    static bool IsReadCoil(int iFunctionCode);
    static bool IsReadInput(int iFunctionCode);
    static bool IsReadHoldRegisters(int iFunctionCode);
    static bool IsReadInputRegisters(int iFunctionCode);

    static bool IsWrite(int iFunctionCode);
    static bool IsWriteOneCoil(int iFunctionCode);
    static bool IsWriteOneHoldRegister(int iFunctionCode);
    static bool IsWriteSomeHoldRegisters(int iFunctionCode);
};


#endif //FUNCTION_CODE_H


